
<?
        $results = array();
        require_once('../inc/accounts.php');
        if(isset($_REQUEST['returnUrl']))
                $_SESSION['returnUrl'] = $_REQUEST['returnUrl'];
        if(!isset($_SESSION['returnUrl']) && isset($_SERVER['HTTP_REFERER']))
                $_SESSION['returnUrl'] = $_SERVER['HTTP_REFERER'];
                       
        if(isset($_POST['email']))
        {
                $row = $_POST;
                $results = DoLogin($_POST['email'], $_POST['password']);
                if($results === true)
                {
                        $returnUrl = !empty($_SESSION['returnUrl']) ? $_SESSION['returnUrl'] : '../Home/';
                        header("Location: $returnUrl");
                        die();
                }
        }else{
                $row = array('email'=>null, 'password'=>null);
        }
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Login</title>
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" type="text/css" href="../inc/bootstrap.css">
    <style type="text/css" >
        .error { color: red; }
                input.error { border-color: red; }
    </style>
</head>

<body>
        <? include('../inc/header.php'); ?>
        <div class="container">
                        <? include('../inc/nav.php'); ?>
            <div id="contents">
               
                <dl class="error">
                        <? foreach ($results as $key => $value): ?>
                                                <dt><?=$key?></dt>
                                                <dd><?=$value?></dd>
                                        <? endforeach; ?>
                </dl>
               
                <form class="form-horizontal" method="post" action="login.php">
                    <div class=" control-group">
                        <label class="control-label" for="email">Email or Phone Number:</label>
                        <div class="controls">
                            <input      type="text" name="email" id="email" value="<?=$row['email']?>"
                                                                        class="required  <?=isset($results['email']) ? 'error' : '' ?>"
                                                         />
                             <span class="error"><?=isset($results['email']) ? $results['email'] : '' ?></span>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="password">Password:</label>
                        <div class="controls">
                            <input      type="text" name="password" id="password" value="<?=$row['password']?>"
                                        class="<?=isset($results['password']) ? 'error' : '' ?>"
                            />
                             <span class="error"><?=isset($results['password']) ? $results['password'] : '' ?></span>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                                <input class="btn btn-primary" type="submit" value="Login" />
                        </div>
                    </div>
                </form>
           </div>
       </div>
       <script type="application/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js">
           </script>
       <script type="application/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
           </script>
       <script type="text/javascript">
                        $(function(){
                                $("form").validate();
                        });
           </script>
</body>
</html>
